package mxbean;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

/**
 * @author ChangLiang
 * @date 2021/4/2
 */
public class ThreadMXBeanTest {

    @Test
    @DisplayName("test")
    public void test(){

        ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
        long[] threadIds = mbean.getAllThreadIds();
        for (long threadId : threadIds) {
            ThreadInfo threadInfo = mbean.getThreadInfo(threadId);
            System.out.println(threadInfo.getThreadName());
        }
    }
}
